package net.cocotea.sqltoy.lambda.util;

import net.cocotea.sqltoy.lambda.common.SqlCharter;
import net.cocotea.sqltoy.lambda.func.SFunction;
import org.sagacity.sqltoy.utils.StringUtil;

import java.util.StringJoiner;

/**
 * Lambda工具类
 * 
 * @author CoCoTea
 * @since 0.0.3
 */
public class LambdaUtils {

    public static <T> StringJoiner getCols(SFunction<T, Object>[] cols) {
        if (cols == null || cols.length == 0) {
            return null;
        }
        StringJoiner joiner = null;
        for (SFunction<T, Object> col : cols) {
            if (joiner == null) {
                joiner = new StringJoiner(SqlCharter.COMMA);
            }
            String filedName = ColUtils.filedName(col);
            if (StringUtil.isBlank(filedName)) {
                continue;
            }
            joiner.add(filedName);
        }
        return joiner;
    }

    public static <T> String getCol(SFunction<T, Object> col) {
        String filedName = ColUtils.filedName(col);
        if (StringUtil.isBlank(filedName)) {
            return null;
        }
        return filedName;
    }

}
